// pages/htjc/htjc.js
const app = getApp()
const pathUrl = app.globalData.pathUrl;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    proAry: ['发起公证', '活体检测', '电子签名', '收执已阅'],
    showHtjc: true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    var that = this;
    var userId = wx.getStorageSync('userId')
    var caseNumber = wx.getStorageSync('caseNumber')
    var writNumber = wx.getStorageSync('writNumber')
    var realName = wx.getStorageSync('realName')
    var orderNo = wx.getStorageSync('orderNo')

    that.setData({
      userId: userId,
      caseNumber: caseNumber,
      writNumber: writNumber,
      realName: realName,
      orderNo: orderNo

    })
    this.get04();
  },
  get04: function () {
    var that = this;
    var telphone = that.data.telphone;
    wx.request({
      url: pathUrl + '/gzgl/fxyGzgl04/list',
      method: 'GET',
      data: {
        query07: that.data.orderNo,
      },
      success: function (res) {
        console.log(res.data.result.records);
        var list = res.data.result.records[0];

        wx.setStorageSync('caseNumber', list.query16);
        wx.setStorageSync('writNumber', list.query17);
        console.log(list.query16)
        that.setData({
          status: list.query11
        })
        // if (res.data.success) { // 登陆成功
        //   wx.setStorageSync('loginInfo', JSON.stringify(res.data.result));
        //   wx.navigateTo({
        //     url: "/pages/index/index"
        //   })
        // } else { // 登陆失败
        //   wx.showToast({
        //     title: res.data.message,
        //     icon: 'fail',
        //     duration: 1000
        //   });
        // }
      },
      fail: function (res) { }
    });
  },
  // 开始活体检测
  //    pushUrl	否	String(128)		认证成功后的异步推送地址，支持HTTP/HTTPS，需进行URLEncoder，URL不允许带参
  //    appletId	是	String(64)		回调小程序APPID
  //    appletPath	是	String(128)		回调小程序PATH
  //    appletExtraData	否	String(256)		回调小程序参数
  //    appletEnvVersion	否	String(32)		回调小程序版本
  btnStart() {
    var that = this;
    wx.showLoading({
      title: '跳转中',
    })
    var userId = that.data.userId;

    var caseNumber = wx.getStorageSync('caseNumber')
    var writNumber = wx.getStorageSync('writNumber')
    var caseNumber = that.data.caseNumber;
    var writNumber = that.data.writNumber;
    // var pushUrl = that.data.pushUrl;
    var appletId = 'wx489d91cb36c352bb';
    var appletPath = '/pages/index/index';
    // var appletExtraData = that.data.appletExtraData;
    // var appletEnvVersion = that.data.appletEnvVersion;
    var data = {
      userId: userId,
      caseNumber: caseNumber,
      writNumber: writNumber,
      // pushUrl: pushUrl,
      appletId: appletId,
      appletPath: appletPath,
      // appletExtraData: appletExtraData,
      // appletEnvVersion: appletEnvVersion,
    }
    console.log('123323')
    wx.request({
      url: pathUrl + '/fxy/1/doSignAppletIdentityVerify',
      method: 'POST',
      data: data,
      success: function (e) {
        console.log(e)
        console.log(JSON.parse(e.data.message).resultDesc)
        if (!e.data.success) {
          wx.hideLoading()
          wx.showModal({
            title: '提示',
            content: JSON.parse(e.data.message).resultDesc,
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                wx.reLaunch({
                  url: '/pages/index/index',
                })
              }
            },
            fail: function (res) { },
            complete: function (res) { },
          })
          return false
        }
        console.log(JSON.parse(e.data.message).resultData.appletId)
        var id = JSON.parse(e.data.message).resultData.appletId;
        var path = JSON.parse(e.data.message).resultData.appletPath;
        var sn = JSON.parse(e.data.message).resultData.sn;
        console.log(sn)
        console.log(path)
        wx.setStorageSync('sn', sn)
        wx.hideLoading();
        wx.navigateToMiniProgram({
          appId: id,
          path: path,
          // extraData: {
          //   from: ''
          // },
          envVersion: 'release',
          success(res) {
            console.log(res)
            // 打开其他小程序成功同步触发
            wx.showToast({
              title: '跳转成功'
            })
          },
          // fail:function(){
          //   wx.showModal({
          //     title: '提示',
          //     content: '跳转失败',
          //     showCancel:false,
          //   })
          // }
        })
      }
    })
    // this.setData({
    //   showHtjc: false,
    // })
  },
  // btnStart() {
  //   var that = this;
  //   wx.navigateTo({
  //     url: '/pages/',
  //   })
  // },
  result: function () {
    wx.navigateTo({
      url: '/pages/resultCheck/resultCheck',
    })
  },
  navigateToMiniProgram: function () {
    wx.navigateToMiniProgram({
      appId: 'wx3cbba435621590ab',
      path: 'pages/index/index',
      extraData: {
        from: 'xxxxx'
      },
      envVersion: 'develop',
      success(res) {
        // 打开其他小程序成功同步触发
        wx.showToast({
          title: '跳转成功'
        })
      }
    })
  },
  // 按住拍 
  startAction: function () {
    wx.navigateTo({
      url: '../addr/addr'
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})